<template>
  <!--  <h2>密级审批</h2>-->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="题名" prop="title">
        <el-input v-model="queryParams.title" placeholder="请输入题名" clearable style="width: 240px" />
      </el-form-item>

      <el-form-item label="档案门类" prop="categoryId">
        <treeselect v-model="queryParams.categoryId" :options="deptOptions" clearable style="width: 240px"
          placeholder="请选择档案门类" :disable-branch-nodes="true" noResultsText="暂无数据" :normalizer="normalizerCategoryID"/>
      </el-form-item>

      <el-form-item label="保管期限" prop="mjChange">
        <el-select v-model="queryParams.mjChange" placeholder="请选择" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.BGQX" :key="dict.value" :label="dict.label" :value="dict.label" />
        </el-select>
      </el-form-item>

      <el-form-item label="当前环节" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择" clearable style="width: 240px">
          <el-option v-for="item in stateOption" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList" :height="tableHeight" @selection-change="handleSelectionChange"
      @cell-dblclick="handleClick">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" :index="table_index" width="55" align="center" prop="id" />
      <el-table-column label="题名" prop="title" align="center" />
      <el-table-column label="档案门类" prop="categoryName" align="center" />
      <el-table-column label="保管期限" prop="mjChange" align="center" />
      <el-table-column label="创建人" prop="creator" align="center" />
      <el-table-column label="创建时间" prop="createTime" align="center" />
      <el-table-column label="审批结果" prop="task" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.task == '0'">不同意</span>
          <span v-else-if="scope.row.task == '1'">同意</span>
          <span v-else-if="scope.row.task == '3'">取消审批</span>
        </template>
      </el-table-column>
      <el-table-column label="当前环节" prop="state" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.state == 1 ? '审批中' : '审批完成' }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <Detail :title="title" :open="detailOpen" @closeDelDialog="closeDelDialog" ref="detailRef"></Detail>
  </div>
</template>

<script>
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { getExamineList, listGROUPTree } from "@/api/archive/archivalAppraisal/bgqxIdentify/bgqxExamineApprove.js";
import estimateTableHeight from "@/mixins/estimateTableHeight";
import Detail from "@/views/archive/archivalAppraisal/bgqxIdentify/bgqxExamineApprove/detail";


export default {
  name: "index",
  components: { Detail, Treeselect },
  archive_Dicts: ['BGQX'],
  mixins: [estimateTableHeight], // 混入方法
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: undefined,
        categoryId: undefined,
        mjChange: undefined,
        state: undefined
      },
      // 显示搜索条件
      showSearch: true,
      // 树选项
      deptOptions: [],
      stateOption: [
        { value: '1', label: '审批中' },
        { value: '2', label: '审批完成' },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      dataList: [],
      total: 0,
      title: '保管期限审批',
      detailOpen: false,
      noClick: true,
    }
  },
  created() {
    this.getDeptTree()
    this.getList()
  },
  methods: {
    // 只能选择数据下面有children 的数据，没有children的时候禁用
    normalizerCategoryID(node) {
      if (node.nodeType == 'fonds') {
        if (node.children == undefined || node.children == null || !node.children.length) {

          node['isDisabled'] = true;
        }

      }
      if (node.children == null || node.children == undefined || !node.children.length) {
        delete node.children;
      }
      return node
    },
    // 获取档案门类树
    getDeptTree() {
      listGROUPTree().then(response => {
        this.deptOptions = response.data;
      })
    },
    table_index(index) {
      return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
    },
    getList() {
      if (this.noClick) {
        this.noClick = false
        getExamineList(this.queryParams).then(response => {
          this.dataList = response.rows
          this.total = response.total
          this.loading = false
          setTimeout(() => {
            this.noClick = true
          }, 300)
        }).catch(() => {
          setTimeout(() => {
            this.noClick = true
          }, 300)
        })
      }
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList()
    },
    // 重置按钮
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 双击列表数据
    handleClick(row) {
      this.$nextTick(() => {
        this.$refs.detailRef.activeName = '0'
        this.$refs.detailRef.init(row)
      })
      this.detailOpen = true
    },
    closeDelDialog() {
      this.detailOpen = false
      console.log(123)
      this.handleQuery()
    }
  }
}
</script>

<style scoped></style>
